* Set current directory and open log
cd "I:\Seagate Sync\VOL\My Documents\Research\Current projects\prlx\Posted\101113 EUP publication\Data analysis"
capture log close
log using "prlx-v01-analysis03", replace text


********************************************************************************************
* Figures and tables for paper section "The outcome and duration of Council decision-making"
********************************************************************************************


* Project and author information
********************************
* Project:		prlx
* Programme:	prlx-v01-analysis03.do
* Date:			20 November 2010
* Author:		Frank Haege, University of Limerick
* Contact:		frank.haege@ul.ie 

* Do-file description
*********************
* This do-file generates the figures and tables presented and referred to in the section
* "The outcome and duration of Council decision-making". It relies on the dataset and variables
* generated by the do-file "prlx-v01-analysis02.do".


* Clear memory  
**************
version 11.0
clear all
macro drop _all
set more off

* Load dataset
use "prlx-v01-analysis02.dta", clear
des, short


* Figure 6: Outcome of Council decision-making by start year, 1976-2009
***********************************************************************

* Generate dummy variables for type of Council decision-making outcome
tab cenddated, m gen(cenddated_)

* Plot relative frequency of type of Council decision-making outcome over time
graph bar cenddated_1 cenddated_2 cenddated_3 cenddated_4 cenddated_5, /*
	*/ over(year, gap(40)) percentages stack horizontal /*
	*/ ytitle("Percent") ysize(6) xsize(4) scale(0.9) /*
	*/ legend(rows(1) position(6) label(1 "Adoption") label(2 "Part. adopt.") /*
	*/ label(3 "Withdrawal") label(4 "Replacement") label(5 "Pending") stack region(lcolor(none))) /*
	*/ bar(1, color(gs14)) bar(2, color(gs6)) bar(3, color(gs9)) bar(4, color(gs12)) bar(5, color(gs3))


* Table SI-6.1: Outcome of Council decision-making by start year, 1976-2009 (rel. frequencies)
**********************************************************************************************

* Tabulate relative frequency of type of Council decision-making outcome over time
tab year cenddated, m row


* Table SI-6.2: Outcome of Council decision-making by start year, 1976-2009 (abs. frequencies)
**********************************************************************************************

* Tabulate absolute frequency of type of Council decision-making outcome over time
tab year cenddated, m


* Table SI-6.3: Type of Council decision-making outcome, 1976-2007
******************************************************************

* Tabulate absolute frequency of type of Council decision-making outcome
tab cenddated if year < 2008, m

	
* Figure 7: Duration of Council decision-making by start year, 1976-2007
************************************************************************

* Generate Council decision-making duration variable
generate dur = cenddate - datetrans
sum dur
format datetrans %td 
label variable dur "Duration (days)"

* Correct errors in duration variable
list webno cenddate datetrans cenddated if dur < 0
replace dur = cenddate - dateadop if datetrans > cenddate
sum dur,d
		
* Check dates of withdrawal
format cenddate %d
tab cenddate if cenddated == 3, m
tab cenddate if cenddated == 4, m
tab cenddate if cenddated == 1 in 1/100, m	
* Withdrawal dates are highly clustered

* Plot duration over time without outside values
graph hbox dur if (cenddated == 1 | cenddated == 2) & year < 2008, nooutsides over(year) note("") /*
	*/ ytitle("Duration (days)") ysize(6) xsize(4) ylabel(0 365:1460)
	
		
* Table SI-7: Duration of Council decision-making by start year, 1976-2007
**************************************************************************

* Tabulate duration statistics over time
tabstat dur if (cenddated == 1 | cenddated == 2) & year < 2008, by(year) stats(q iqr) format(%9.1f)	


* Figure SI-7.1: Duration of Council decision-making by outcome
***************************************************************

* Plot duration by type of Council decision-making outcome
graph hbox dur if cenddated != 5, over(cenddated) nooutsides note("") /*
	*/ ytitle("Duration (days)") ylabel(0 1095:5475) nofill scale(1.3)

	
* Figure SI-7.2: Distribution of duration of Council decision-making, 1976-2007
*******************************************************************************

* Plot density of Council decision-making duration
kdensity dur if (cenddated == 1 | cenddated == 2) & year < 2008, bwidth(30) title("") note("") scale(1.7)
	

* Figure SI-7.3: Duration of Council decision-making by start year, 1976-2007 (including outside values)
********************************************************************************************************

* Plot duration over time including outside values
graph hbox dur if (cenddated == 1 | cenddated == 2) & year < 2008, over(year) note("") /*
	*/ ytitle("Duration (days)") ysize(6) xsize(4) marker(1, msymbol(oh)) ylabel(0 1825:5475)


* Figure 8: Median duration of Council decision-making by start year, 1976-2007
*******************************************************************************

* Generate yearly median duration of Council decision-making variable
sort year
by year: egen dur_med = pctile(dur) if cenddated == 1 | cenddated == 2, p(50)

* Plot median duration over time
twoway (scatter dur_med year if year < 2008, /*
	*/ msymbol(O) connect(direct) lpattern(-) lcolor(orange)) /*
	*/ (mspline dur_med year if year < 2008, bands(6) lcolor(white) ) /*
	*/ , xlabel(1976 1980 1985:2000 2005) ylabel(0 90:450) xtitle("Year") ytitle("Median duration (days)") /*
	*/ legend(ring(0) pos(11) cols(1) order(1 "Observed medians" 2 "Median splines" ) region(lcolor(none)))
		
		
* Figure 9: Median duration of Council decision-making under different legislative procedures, 1976-2007
********************************************************************************************************

* Generate yearly median duration of Council decision-making by procedure variable
sort year procedurec
by year procedurec: egen dur_proc_med = pctile(dur) if cenddated == 1 | cenddated == 2, p(50)

* Plot median duration by procedure over time
twoway (scatter dur_proc_med year if year < 2008 & procedurec == 1, /*
	*/ msymbol(O) connect(direct)) /*
	*/ (scatter dur_proc_med year if year > 1986 & year < 2000 & procedurec == 2, msymbol(s) mcolor(orange) connect(l) lcolor(orange)) /*
	*/ (scatter dur_proc_med year if year > 1992 & year < 2008 & procedurec == 3, msymbol(T) mcolor(red) connect(l) lcolor(red)) /*
	*/ (scatter dur_med year if year > 1986 & year < 2008, msymbol(i) mcolor(white) connect(l) lpattern(-) lcolor(white)) /*
	*/ , xlabel(1976 1980 1985:2005) ylabel(0 180:720) xtitle("Year") ytitle(" " "Median duration (days)") /*
	*/ legend(ring(0) pos(11) cols(1) order(3 "Codecision" 2 "Cooperation" 1 "Consultation" 4 "All procedures") region(lcolor(none)))

	
* Exit do-file
log close
exit
